package com.fh.shop.api.book.controller;

import com.fh.shop.api.book.biz.IBookService;
import com.fh.shop.api.book.param.BookQueryParam;
import com.fh.shop.api.book.po.Book;
import com.fh.shop.api.common.DataTableResult;
import com.fh.shop.api.common.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/books")
@CrossOrigin
@Api(tags = "图书restful接口",description = "图书增删改查restful接口")
public class BookRestController {

    @Resource
    private IBookService bookService;

    @ApiOperation("增加接口")
    @PostMapping
    public ServerResponse add(Book book){
     return bookService.addBook(book);
    }

    @ApiOperation("根据id删除接口")
    @ApiImplicitParam(name = "id",value = "图书ID",dataType = "java.lang.Long",required = true,example = "0")
    @DeleteMapping("{id}")
    public ServerResponse delete(@PathVariable Long id){
        return bookService.deleteBook(id);
    }

    @ApiOperation("批删接口")
    @DeleteMapping
    public ServerResponse deleteBatch(String ids){
        return bookService.deleteBatch(ids);
    }

    @ApiOperation("回显接口")
    @GetMapping
    public ServerResponse find(Long id){
        return bookService.findBook(id);
    }

    @ApiOperation("修改接口")
    @PutMapping
    public ServerResponse update(@RequestBody Book book){
        return bookService.updateBook(book);
    }

//    @RequestMapping(value = "/books/{id}",method = RequestMethod.DELETE)
//    public DataTableResult findList(@PathVariable BookQueryParam bookQueryParam){
//        return bookService.findList(bookQueryParam);
//    }


}
